package Eyjafjalla.action;

import Eyjafjalla.patch.CloudPatch;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;

import java.util.ArrayList;

public class UrgentPrestoAction extends AbstractGameAction {
    public UrgentPrestoAction(AbstractCreature target, DamageInfo info){
        this.setValues(target,info);
        this.actionType = ActionType.CARD_MANIPULATION;
        this.duration = startDuration = Settings.ACTION_DUR_FAST;
        this.info = info;
    }

    DamageInfo info;

    @Override
    public void update() {
        if(duration==startDuration){
            ArrayList<AbstractCard> copy = new ArrayList<>(CloudPatch.cloudGroup.group);
            int amt = copy.size();
            for(AbstractCard c:copy){
                CloudPatch.resetBeforeRemove(c);
                if (AbstractDungeon.player.hoveredCard == c) {
                    AbstractDungeon.player.releaseCard();
                }
                c.untip();
                c.unhover();
                c.stopGlowing();
                c.lighten(true);
                c.setAngle(0F);
                AbstractDungeon.player.drawPile.addToRandomSpot(c);
            }

            for(int i =0;i<amt;i++){
                addToTop(new DamageAction(this.target,this.info,AttackEffect.SLASH_DIAGONAL));
            }
        }


        this.tickDuration();
    }
}
